<template>
	<view>
		<u-sticky bgColor="#fff">
			<view class="dingbu">
				<view class="" :style="{paddingTop:menutop+'rpx'}">
					<view class="">
						<view class="ershiba xiaocheng">
							<text class="ershiba xiaolv">青呼我为</text>
						</view>
					</view>
					<view class="flexbetween margin_top">
						<view class="flexleft"
							style="padding:15rpx 30rpx;background: #FFFFFF;border-radius: 12rpx;border: 1rpx solid #FFFFFF;width: 65%;">
							<view class="margin_right1">
								<u-icon name="search" size="28"></u-icon>
							</view>
							<input placeholder="输入关键词" type="text" v-model="keywords" confirm-type="search" @confirm="init"/>
						</view>
						<view class="flexright">
							<image style="width: 25rpx;height: 26rpx;margin-right: 6rpx;"
								src="../../static/image/system/jb.png" mode="">
							</image>
							<view class="strongtext xiaohei">青统币:
								<text class="titletext xiaohei" v-if="userInfo">{{userInfo.score || "0"}}</text>
								<text class="titletext xiaohei" v-if="!userInfo">0</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</u-sticky>
		<view class="mainpadding" style="padding-bottom: 150rpx;">
			<u-notice-bar :text="text1" direction="column" @click="enternews($event)"></u-notice-bar>
			<!-- 福利上新 -->
			<view class="">
				<view class="flexbetween margin_top">
					<view class="flexleft">
						<view class="allline margin_right1"></view>
						<view class="sanshier xiaohei">福利上新</view>
					</view>
					<!-- <u-icon name="arrow-right" color="#666666"></u-icon> -->
				</view>
				<view class="flexleft flex_wrap">
					<view class="sanshis flexcenter margin_top" v-for="item in list.data" :key="item.id" @click="jumpdetail('/pages/qingfuli/shangpinxq?id=',item.id)">
						<view class="">
							<image style="width: 214rpx;height: 192rpx;border-radius:12rpx 12rpx 0 0;"
								:src="item.image_text" mode=""></image>
							<view class="ffffff mainpadding2s" style="border-radius:0 0 12rpx 12rpx;">
								<view class="ershil xiaohei xiankuan" style="width: 160rpx;">{{item.name}}</view>
								<view class="flexleft margin_top1">
									<image style="width: 26rpx;height: 26rpx;" src="../../static/image/system/jb.png"
										mode=""></image>
									<view class="smalltext xiaohong margin_left1">{{item.price}}青统币</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<tabbar :current="4"></tabbar>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				menutop: 0,
				text1: [],
				newsData:[],
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				keywords:"",
				userInfo:{}
			}
		},
		onShareAppMessage: function(options) {
			return {
				title: '青年汇',
				imageUrl: '',
				path: '/pages/qingzixun/qingzixun'
			}
		},
		onShareTimeline: function() {
			return {
				title: '青年汇',
				imageUrl: '',
				path: '/pages/qingzixun/qingzixun'
			}
		},
		onLoad() {
			// #ifdef MP-WEIXIN
			this.menutop = uni.getMenuButtonBoundingClientRect().top * 2
			// #endif
			this.getnews()
			this.init()
		},
		onShow() {
			if (httpRequest.checkIsLogin()) {
				this.getuser()
			}else{
				this.userInfo = null
			}
		},
		methods: {
			getuser(){
				httpRequest.request('/api/user/index', 'GET', {}).then(res => {
					if (res.code == 1) {
						this.userInfo = res.data
						uni.setStorageSync("invite_code", res.data.invite_code)
					} else {
						this.userInfo = null
					}
				})
			},
			init(isPage, page) {
				httpRequest.request("/api/goodscl/goodsIndex", 'GET', {
					page: page || 1,
					limit: this.limit,
					keywords:this.keywords
				}, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = this.list;
						if (isPage == true) {
							this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							this.list.data = resList.data;
						}
					}
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			getnews() { //滚动消息
				httpRequest.request('/api/index/noticeIndex', 'GET', {
					page: 1,
					limit: 12,
					type:2
				}, false, false, true).then(res => {
					let arr = []
					res.data.data.forEach(item => {
						arr.push(item.name)
					})
					this.text1 = arr
					this.newsData = res.data.data
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			enternews(index) {
				uni.navigateTo({
					url: "/pages/qingzixun/gonggaoxq?id=" + this.newsData[index].id
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.dingbu {
		padding: 0 30rpx 30rpx;
		background-size: 100% 100%;
		width: 100%;
		box-sizing: border-box;
		background-image: url('../../static/image/system/toub.png');
	}
</style>